package Leetcode;

import tree.TreeNode;

public class sortedArrayToBST {
    public TreeNode sortedArrayToBST(int[] nums) {
        int length = nums.length;
        if (length == 0){
            return null;
        }
        return arrayToBST(nums, 0, length);
    }
    public TreeNode arrayToBST(int[] nums, int start, int end){
        if (start >= end){
            return null;
        }
        int mid = (start + end) / 2;
        TreeNode node = new TreeNode(nums[mid]);
        node.left = arrayToBST(nums, start, mid);
        node.right = arrayToBST(nums, mid + 1, end);
        return node;
    }
}
